home *** CD-ROM | disk | FTP | other *** search
- /* LogDataFormatTimestamp.c */
- /*
- * LogDataFormatTimestamp.c
- * Copyright © 1992-94 Apple Computer Inc. All Rights Reserved.
- * Programmed by Martin Minow,
- * Internet: minow@apple.com
- * AppleLink: MINOW
- *
- * Edit History
- * 93.01.09 MM First public release
- * 93.07.09 MM Reformatted for 80-column page. No substantive changes.
- * 94.12.10 MM Redone (from AuditEntryFormat) for the Driver Log.
- */
- #include "LogLibrary.h"
- #ifndef THINK_C /* Temp until headers stabalize */
- #include <Types.h>
- #include <OSUtils.h>
- #endif
-
- #define NUL '\0'
- #define AppendChar(result, theChar) do { \
- StringPtr _dst = (result); \
- _dst[++_dst[0] & 0xFF] = theChar; \
- } while (0)
- static void AppendUnsignedLeadingZeros(
- StringPtr result,
- unsigned long value,
- short digits,
- short terminator
- );
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * FormatLogEntryTimestamp
- *
- * Format a converted log entry timestamp (prepared by ConvertLogEntryTimestamp). The
- * result is appended to result as a fixed-length string: "yyyy.mm.dd hh.mm.ss.msec"
- * FormatLogEntryTimestamp does not use the system date formatting routines. Note
- * that the fractional seconds are truncated to the nearest lower millisecond, even
- * though nanosecond precision is potentially available. This function does not
- * require a MixedMode switch.
- */
- pascal void
- FormatLogEntryTimestamp(
- StringPtr result, /* Append to this string */
- const DateTimeRec *dateTimeRec, /* Year, Month, Day etc. */
- UInt32 residualNanoseconds /* Fractional second */
- )
- {
- /*
- * Choose kSecondFraction 1000000L to convert nanoseconds to milliseconds
- * Choose kSecondFraction 1000L to convert nanoseconds to microseconds
- * Choose kSecondFraction 1L to display nanoseconds in all their glory.
- */
- #define kSecondFraction 1000L
- AppendUnsignedLeadingZeros(result, dateTimeRec->year, 4, '.');
- AppendUnsignedLeadingZeros(result, dateTimeRec->month, 2, '.');
- AppendUnsignedLeadingZeros(result, dateTimeRec->day, 2, ' ');
- AppendUnsignedLeadingZeros(result, dateTimeRec->hour, 2, ':');
- AppendUnsignedLeadingZeros(result, dateTimeRec->minute, 2, ':');
- AppendUnsignedLeadingZeros(result, dateTimeRec->second, 2, '.');
- #if kSecondFraction == 1000L /* Microseconds */
- AppendUnsignedLeadingZeros(result, residualNanoseconds / 1000L, 6, NUL);
- #elif kSecondFraction == 1000000L /* Milliseconds */
- AppendUnsignedLeadingZeros(result, residualNanoseconds / 1000000L, 3, NUL);
- #else /* Nanoseconds */
- AppendUnsignedLeadingZeros(result, residualNanoseconds, 9, NUL);
- #endif
- }
-
- /*
- * Output an n-digit decimal value with leading zeros.
- */
- static void
- AppendUnsignedLeadingZeros(
- StringPtr result,
- unsigned long value,
- short digits,
- short terminator
- )
- {
- if (--digits > 0)
- AppendUnsignedLeadingZeros(result, value / 10, digits, NUL);
- AppendChar(result, (value % 10) + '0');
- if (terminator != NUL)
- AppendChar(result, terminator);
- }
-
-